#include <iostream>
#include <vector>
#include <string>
#include <thread>
#include <mutex>
#include "utils.h"

// 扫描单个IP的指定端口范围
void scan_ports(const std::string& ip, int start_port, int end_port, std::mutex& print_mutex);

int main(int argc, char* argv[]) {
    std::cout << "PortScan v1.0" << std::endl;
    print_banner();
    
    if (argc < 2) {
        std::cout << "Usage: " << argv[0] << " <IP1> [IP2] [IP3] ..." << std::endl;
        std::cout << "Example: " << argv[0] << " 192.168.1.1 10.0.0.1" << std::endl;
        return 1;
    }
    
    std::vector<std::string> ip_addresses;
    for (int i = 1; i < argc; i++) {
        ip_addresses.push_back(argv[i]);
    }
    
    std::cout << "Starting scan of " << ip_addresses.size() << " IP address(es)..." << std::endl;
    
    std::mutex print_mutex;
    std::vector<std::thread> threads;
    
    // 为每个IP创建一个扫描线程
    for (const auto& ip : ip_addresses) {
        threads.push_back(std::thread(scan_ports, ip, 1, 65535, std::ref(print_mutex)));
    }
    
    // 等待所有线程完成
    for (auto& t : threads) {
        if (t.joinable()) {
            t.join();
        }
    }
    
    std::cout << "Scan completed!" << std::endl;
    return 0;
}